package com.zmh.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.zmh.entity.BookEntity;


/** 
 * 书籍信息数据库操作类
 * @author zhoumh
 * @version 创建时间：2018年7月15日 上午10:10:10 
 * @Description 
*/
@Mapper
public interface BookMapper {
	@Select("SELECT * FROM book")
	@Results({
		@Result(property = "id",  column = "id"),
		@Result(property = "uuid", column = "uuid"),
		@Result(property = "name", column = "name"),
		@Result(property = "author", column = "author"),
		@Result(property = "description", column = "description")
	})
	List<BookEntity> getAll();
	
	/**
	 * 根据备注信息中的booklinkid找寻书籍信息
	 * @return: BookEntity
	 * @author: zhoumh
	 * @version: 创建时间：2018年7月22日 下午10:11:42 
	 * @Description:
	 */
	@Select("SELECT * FROM book WHERE description = #{id}")
	BookEntity getOneByDesc(String id);
	
	/**
	 * 根据书籍名称查询书籍信息
	 * @return: BookEntity
	 * @author: zhoumh
	 * @version: 创建时间：2018年7月22日 下午10:12:06 
	 * @Description:
	 */
	@Select("SELECT * FROM book WHERE name = #{name}")
	BookEntity getOneByName(String name);
	
	/**
	 * 根据书籍uuid查询书籍信息
	 * @return: BookEntity
	 * @author: zhoumh
	 * @version: 创建时间：2018年7月22日 下午10:12:06 
	 * @Description:
	 */
	@Select("SELECT * FROM book WHERE uuid = #{uuid}")
	BookEntity getOneByUuid(String uuid);


	@Insert("INSERT INTO book(uuid,name,author,description) VALUES(uuid(),#{name}, #{author}, #{description})")
	int insert(BookEntity book);

	@Update("UPDATE book SET name=#{name},author=#{author} WHERE uuid =#{uuid}")
	int update(BookEntity book);

	@Delete("DELETE FROM book WHERE uuid =#{uuid}")
	int delete(String uuid);
}
